home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gnugo1_1.lha / gnugo / findcolr.c < prev    next >
C/C++ Source or Header  |  1989-03-07  |  2KB  |  103 lines

  1. /*
  2.                 GNU GO - the game of Go (Wei-Chi)
  3.                 Version 1.1   last revised 3-1-89
  4.            Copyright (C) Free Software Foundation, Inc.
  5.                       written by Man L. Li
  6.                       modified by Wayne Iba
  7.                     documented by Bob Webber
  8. */
  9. /*
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation - version 1.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License in file COPYING for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. Please report any bug/fix, modification, suggestion to
  24.  
  25. mail address:   Man L. Li
  26.                 Dept. of Computer Science
  27.                 University of Houston
  28.                 4800 Calhoun Road
  29.                 Houston, TX 77004
  30.  
  31. e-mail address: manli@cs.uh.edu         (Internet)
  32.                 coscgbn@uhvax1.bitnet   (BITNET)
  33.                 70070,404               (CompuServe)
  34. */
  35.  
  36. #include <stdio.h>
  37.  
  38. #define EMPTY 0
  39.  
  40. extern unsigned char p[19][19];
  41.  
  42. findcolor(i, j)
  43. /* find color for empty piece */
  44. int i, j;
  45. {
  46.  int k, color1, color2;
  47.  
  48. /* check North neighbor */
  49.  color1 = 0;
  50.  k = i;
  51.  do --k;
  52.  while ((p[k][j] == EMPTY) && (k > 0));
  53.  color1 = p[k][j];
  54.  
  55. /* check South neighbor */
  56.  color2 = 0;
  57.  k = i;
  58.  do k++;
  59.  while ((p[k][j] == EMPTY) && (k < 18));
  60.  color2 = p[k][j];
  61.  
  62.  if (color1)
  63.    {
  64.     if ((color1 == color2) || (color2 == 0))
  65.        return color1;
  66.     else
  67.        return 0;  /* cannot determine */
  68.   }
  69.  else
  70.     if (color2)
  71.        return color2;
  72.     else  /* both zero */
  73.        {
  74. /* check West neighbor */
  75.     color1 = 0;
  76.     k = j;
  77.     do --k;
  78.     while ((p[i][k] == EMPTY) && (k > 0));
  79.     color1 = p[i][k];
  80.  
  81. /* check East neighbor */
  82.     color2 = 0;
  83.     k = j;
  84.     do k++;
  85.     while ((p[i][k] == EMPTY) && (k < 18));
  86.     color2 = p[i][k];
  87.  
  88.     if (color1)
  89.       {
  90.        if ((color1 == color2) || (color2 == 0))
  91.           return color1;
  92.        else
  93.           return 0;  /* cannot determine */
  94.      }
  95.     else
  96.        if (color2)
  97.           return color2;
  98.        else
  99.           return 0;
  100.       }
  101. }  /* end findcolor */
  102.  
  103.